package model;

import java.sql.Connection;
import java.util.Properties;

import org.jconfig.Configuration;
import org.jconfig.ConfigurationManager;

import oracle.jdbc.pool.OracleDataSource;

public class CreateConnection {
//	public static final String URL = "jdbc:oracle:thin:dv/dv@192.168.6.112:1521:XE";
	private static OracleDataSource ods = null;

	public static Connection getConnetion() {
		Configuration cf = ConfigurationManager.getConfiguration("MutilThreadConfig.xml");
		String URL = cf.getProperty("URL", "jdbc:oracle:thin:@//192.168.6.112:1521/XE", "JDBC");
		String user = cf.getProperty("USERNAME", "dv", "JDBC");
		String password = cf.getProperty("PASSWORD", "dv", "JDBC");
//		String URL = "jdbc:oracle:thin:@//192.168.6.112:1521/XE";
//		String user = "dv";
//		String password = "dv";
		Connection con;
		try {
			if (ods == null) {
				ods = new OracleDataSource();
                ods.setURL(URL);
                ods.setUser(user);
                ods.setPassword(password);
                // caching parms
                ods.setConnectionCachingEnabled(true);
                ods.setConnectionCacheName("MYCACHE");
                Properties cacheProps = new Properties();
                cacheProps.setProperty("MinLimit", "1");
                cacheProps.setProperty("MaxLimit", "3");
                cacheProps.setProperty("InitialLimit", "1");
                cacheProps.setProperty("ConnectionWaitTimeout", "5");
                cacheProps.setProperty("ValidateConnection", "true");

//                ods.setConnectionCacheProperties(cacheProps);
                ods.setConnectionProperties(cacheProps);
//				ods = new OracleDataSource();
//				ods.setURL(URL);
			}
			//OracleDataSource ods = new OracleDataSource();
			con = ods.getConnection();
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		return con;
	}

}
